﻿using AutoMapper;
using Common.Communal;
using MediatR;
using Scheduling.Api.Write.Application.Command.CalendarCommand;
using Scheduling.Services.Calendars;
using ERP.Domain.Scheduling;

namespace Scheduling.Api.Write.Application.CommandHandlers.CalendarHandler
{
    public class CalendarAddCommandHandler : IRequestHandler<CalendarAddCommand, ApiResult<int>>
    {
        public CalendarAddCommandHandler(ICalendarServices calendar,IMapper mapper)
        {
            Calendar = calendar;
            Mapper = mapper;
        }

        public ICalendarServices Calendar { get; }
        public IMapper Mapper { get; }

        public async Task<ApiResult<int>> Handle(CalendarAddCommand request, CancellationToken cancellationToken)
        {
            var list = Mapper.Map<Calendar>(request);
            return await Calendar.AddCalendar(list);
        }
    }
}
